package com.resou.reader.mine.vipcenter.paysuccess;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.resou.reader.MainActivity;
import com.resou.reader.R;
import com.resou.reader.data.vip.model.VipPrivilege;
import com.resou.reader.mine.vipcenter.MonthlyVipActivity;
import com.resou.reader.utils.eventbus.MessageEvent;

import org.greenrobot.eventbus.EventBus;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 支付成功页面
 */
public class PaySuccessActivity extends AppCompatActivity {

    @BindView(R.id.tvCoupon)
    TextView tvCoupon;
    @BindView(R.id.llCoupon)
    LinearLayout llCoupon;
    @BindView(R.id.llLook)
    LinearLayout llLook;

    public static void start(Context context, String coupon) {
        Intent starter = new Intent(context, PaySuccessActivity.class);
        starter.putExtra("coupon", coupon);
        context.startActivity(starter);
    }

    @BindView(R.id.tvTitle)
    TextView tvTitle;

    /**
     * 启动方法
     *
     * @param context
     */
    public static void start(Context context) {
        Intent starter = new Intent(context, PaySuccessActivity.class);
        context.startActivity(starter);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_pay_success);
        ButterKnife.bind(this);
        tvTitle.setText("VIP开通成功");
        if ("0".equals(getIntent().getStringExtra("coupon"))) {
            llCoupon.setVisibility(View.GONE);
            llLook.setVisibility(View.GONE);
        } else {
            llCoupon.setVisibility(View.VISIBLE);
            llLook.setVisibility(View.VISIBLE);
            tvCoupon.setText(getIntent().getStringExtra("coupon") + "热券");
        }
    }

    @OnClick({R.id.ivBack, R.id.tvLookBook})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.ivBack:
                EventBus.getDefault().post(new VipPrivilege());
                finish();
                break;
            case R.id.tvLookBook:
                MonthlyVipActivity.start(this, true);
                finish();
                break;
        }
    }
}
